package com.steptime.framework.spring.task;

import cn.hutool.core.date.DateUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
@EnableAsync
@EnableScheduling
public class AppConfig {

  /**
   * 自上次执行结束后隔N毫秒执行
   */
  @Scheduled(fixedDelay = 1000)
  public void doSomething() {
    // something that should run periodically
    System.out.println("execute time:"+ DateUtil.date());
  }

  /**
   * 每隔N毫秒执行一次
   */
  @Scheduled(fixedRate = 1000)
  public void fixedRate() {
    // something that should run periodically
    System.out.println("execute time:"+ DateUtil.date());
  }

  @Scheduled(cron = "0/5 * * * * *")
  public void cron() {
    // something that should run periodically
    System.out.println("每5秒执行一次:"+ DateUtil.date());
  }
}